package com.exer;

/**
 * 将一个字符串进行反转，将字符串中指定部分进行反转
 *
 *
 */
public class StringDemo1 {

    //TODO 想想还有别的解法吗  有看哪种效率高
    public static void main(String[] args) {
        String str = "abcdefgdsagc";

        System.out.println(reverseString(str, 1, 6));
    }
    public static String reverseString(String str,int start ,int end){
        //abcdefgdsagc  3,6
        int length = str.length();
        if(start > length || start >= end){
            return str;
        }
        char[] array = str.toCharArray();
        for (int i = start,j = end; i <= j ; i++,j--) {
            char temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }
        return new String(array);
    }


}
